package com.hc.contorl;

import com.github.pagehelper.PageInfo;
import com.hc.service.TbUserService;
import com.hc.service.impl.TbUserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/user_list")
public class UserListContorller extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        int pageNum=Integer.parseInt(req.getParameter("pageNum"));
        int pageSize=Integer.parseInt(req.getParameter("pageSize"));
        TbUserService service=new TbUserServiceImpl();
//        List<TbUser> list=service.findAll();
        PageInfo info=service.listUserByPage(pageNum,pageSize);

        if(pageNum==-1){
            pageNum=info.getPages();
            info=service.listUserByPage(pageNum,pageSize);
        }
        System.out.println("我是info:"+info);
        req.setAttribute("pageInfo",info);
        req.getRequestDispatcher("user_list.jsp").forward(req,resp);

    }

}
